<!DOCTYPE html>
<html>
	<head th:include="/common/head :: head">
		<meta charset="UTF-8">
		<meta name="renderer" content="webkit|ie-comp|ie-stand">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
		<meta http-equiv="Cache-Control" content="no-siteapp" />
	</head>
<body>
	<div class="x-body">
		<form class="layui-form" lay-filter="add_form">
			<div class="layui-form-item">
				<label for=title class="layui-form-label">结果标题<span
					class="x-red">*</span>
				</label>
				<div class="layui-input-inline">
					<input type="text" id="title" name="title" required
						lay-verify="title" autocomplete="off" class="layui-input" >
				</div>
			</div>
			<div class="layui-form-item">
				<label for="predictDate" class="layui-form-label">预测时间
				</label>
				<div class="layui-input-inline">
					<input type="text" id="predictDate" name="predictDate" required
						 autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label for="result" class="layui-form-label">预测结果<span class="x-red">*</span>
				</label>
				<div class="layui-input-block">
                  <textarea lay-verify="result" id="result" name="result" autocomplete="off" required class="layui-textarea"></textarea>
                </div>
			</div>
			<div class="layui-form-item layui-form-text">
              	<label for="predictType" class="layui-form-label">预测类型
				</label>
              <div class="layui-input-block">
		      <input type="radio" name="predictType" value="1" title="部门预测" checked="">
		      <input type="radio" name="predictType" value="2" title="整体预测">
		    </div>
          </div>
			<div class="layui-form-item">
				<label for="L_repass" class="layui-form-label"> </label>
				<button class="layui-btn" lay-filter="add_form" lay-submit="">执行</button>
				<button class="layui-btn" onclick="black()">返回</button>
			</div>
		</form>
	</div>
</body>
<script>
	var addFormData={}
	$(function(){
		initAddForm();
	})
	//初始化添加表单
	function initAddForm(){
		layui.use(['form','layer'],function(){
			$ = layui.jquery;
			var form = layui.form,
			layer = layui.layer;
			//验证规则
			form.verify({
				result:function(value){
					if(value.length <10){
						return '预测结果不得少于10个字符';
					}
				},
				title:function(value){
					if(value.length<5){
						return '结果标题不得少于5个字符';
					}
				}
			});
			//监听提交
			form.on('submit(add_form)',function(data){
				console.log(data);
				addFormData = data.field;
				addPredict()
				return false;
			});
		});
	}
	//添加计划
	function addPredict(){
			$.ajax({
				url:"/predict/doAddPredict",
				type:"post",
				data:{
					"title":addFormData.title,
					"predictDate":addFormData.predictDate,
					"result":addFormData.result,
					"predictType":addFormData.predictType
				},
				success:function(result){
					console.log(JSON.stringify(result));
					if(result.status==0){
						layer.msg(result.msg,function(){
							//关闭弹出层
							var index = parent.layer.getFrameIndex(window.name);
						    parent.layer.close(index);
						    //刷新当前页面
							//parent.location.replace(parent.location.href);
	                    });
					}else{
						layer.msg(result.msg);
					}
				}
			})
	}
	//年月选择器
	layui.use('laydate', function(){
	    var laydate = layui.laydate;
		laydate.render({
		    elem: '#predictDate'
		    ,type: 'month'
		  });
	});
	//返回
	function black(){
		var index = parent.layer.getFrameIndex(window.name);
		parent.layer.close(index);
	}

</script>
</html>